package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.CompanyproductDAO;
import com.chanyachting.emall.domain.base.BaseCompanyproduct;

/**
 * This is the object class that relates to the companyproduct table.
 * Any customizations belong here.
 */
public class Companyproduct extends BaseCompanyproduct {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Companyproduct () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Companyproduct (java.lang.Integer _id) {

		super(_id);
		
		Companyproduct cp=(Companyproduct)new CompanyproductDAO().load(Companyproduct.class, _id);
		
		if(cp!=null){
			
			try {
				BeanUtils.copyProperties(this, cp);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * Constructor for required fields
	 */
	public Companyproduct (
		java.lang.Integer _id,
		java.lang.Integer _companyId,
		java.lang.String _status,
		java.lang.String _createDate) {

		super (
			_id,
			_companyId,
			_status,
			_createDate);
	}
/*[CONSTRUCTOR MARKER END]*/
	
	
	public static List<Companyproduct> listByStatusAndCompanyId(String status,int companyId){
		
		String args[]={status,String.valueOf(companyId)};
		
		return new CompanyproductDAO().find("from Companyproduct where status=? and companyId=? ",args);
	}
	
	public static List<Companyproduct> listByRecommendAndCompanyId(int companyId){
		
		String args[]={String.valueOf(companyId)};
		
		return new CompanyproductDAO().find("from Companyproduct where recommend=1 and companyId=? ",args);
	}
	
	public static List<Companyproduct> listByStatusAndCompanyIdAndChannelId(String status,int companyId,String str){
		
		String args[]={status,String.valueOf(companyId)};
		
		return new CompanyproductDAO().find("from Companyproduct where status=? and companyId=? and channelId in (" + str + ")",args);
	}
	
	public static List<Companyproduct> listByStatus(String status){
		
		String args[]={status};
		
		return new CompanyproductDAO().find("from Companyproduct where status=? ",args);
	}
	
	
	
	public static List<Companyproduct> list(){
		
		return new CompanyproductDAO().find("from Companyproduct");
	}
	
	
	public boolean save(){
		
		new CompanyproductDAO().save(this);
		
		return true;
	}
	
	
	public boolean update(){
		
		new CompanyproductDAO().update(this);
		
		return true;
	}
	
	
	public boolean delete(){
		
		new CompanyproductDAO().delete(this);
		
		return true;
	}
	
	
}